package com.example.demo3.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo3.entity.SpareParts;
import com.example.demo3.mapper.SparePartsMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 备件档案 服务实现类
 * </p>
 *
 * @author xsyuan
 * @since 2020-03-26
 */
@Service
@Transactional
public class SparePartsService extends ServiceImpl<SparePartsMapper, SpareParts>{

    @Resource
    private SparePartsMapper sparePartsMapper;

    /**
     * 分页查询
     * @param pageindex
     * @param pagesize
     * @return
     */
    public Page<SpareParts> getSelectPage(int pageindex, int pagesize){
        Page<SpareParts> page=new Page<SpareParts>().setCurrent(pageindex).setSize(pagesize);
        QueryWrapper<SpareParts> queryWrapper=new QueryWrapper<SpareParts>()
                .orderByDesc("CODE");
        sparePartsMapper.selectPage(page,queryWrapper);
        return page;
    }

    public int countPage(Map<Object,Object> map){
        return sparePartsMapper.countPage(map);
    }

    public List<SpareParts> queryPage(Map<Object,Object> map){
        return sparePartsMapper.queryPage(map);
    }
    /**
     * 新增
     * @param spareParts
     */
    public void insert(SpareParts spareParts){
        spareParts.setId(sparePartsMapper.getUUID());
        sparePartsMapper.insert(spareParts);
    }

    /**
     *修改
     * @param spareParts
     */
    public void update(SpareParts spareParts){
        sparePartsMapper.updateById(spareParts);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(String id){
        QueryWrapper<SpareParts> queryWrapper = new QueryWrapper<SpareParts>()
                .eq("ID",id);
        sparePartsMapper.delete(queryWrapper);
    }

    /**
     * @description  通过Map查询【备件档案】集合
     * @author: xsyuan
     * @date: 2020/3/28 10:51
     * @param  map
     * @return  List
     */
    public List<SpareParts> getByMap(Map<String,Object> map){
        return sparePartsMapper.findByMap(map);
    }
}
